package com.dmall.leetcode303;

import com.dmall.tree.SegmentTree;

public class NumArray1 {

    private SegmentTree<Integer> tree;

    public NumArray1(int[] nums) {
        Integer[] data = new Integer[nums.length];
        for (int i = 0; i < nums.length; i++) {
            data[i] = nums[i];
        }
        tree = new SegmentTree<>(data, (a, b) -> a + b);
    }

    public int sumRange(int i, int j) {
        return tree.query(i, j);
    }
}
